#include<iostream>
#include<math.h>
#include<queue>
#include<string.h>
using namespace std;
queue<int>q;
queue<int>step;
int book[9000005];
int main()
{
	int a,b,temp;
	int limit;
	while( (scanf("%d%d",&a,&b))!=EOF )
	{
		while (!q.empty()) 
			q.pop();
		while (!step.empty()) 
			step.pop();
		memset(book,0,sizeof(book));
		if(b<=a)
		{
			printf("%d\n",a-b);
			return 0;
		}
		limit=b-a;
		q.push(a);
		step.push(0);
		book[a]=1;
		while(1)
		{
			temp=2*q.front();
			if(!book[temp]&&temp<=b+limit)
			{
				book[temp]=1;
				q.push(temp);
				step.push(step.front()+1);
				if(temp==b)
					break;
			}
			temp=q.front()+1;		
			if(!book[temp])
			{
				book[temp]=1;
				q.push(temp);
				step.push(step.front()+1);
				if(temp==b)
					break;
			}
			
			temp=q.front()-1;
			if(temp>=0&&!book[temp])
			{
				book[temp]=1;
				q.push(temp);
				step.push(step.front()+1);
				if(temp==b)
					break;
			}
			
			q.pop();
			step.pop();
		}
		printf("%d\n",step.back());
	}
	return 0;
}
